package com.ymatou.iapi.csim.testcase;

import java.text.SimpleDateFormat;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.GetQueueSessionBean;
import com.ymatou.iapi.csim.parameter.QueuesessionListResp.queuesession;
import com.ymatou.iapi.csim.parameter.SendMessageBean;
import com.ymatou.iapi.csim.parameter.SendMessageCSBean;
import com.ymatou.iapi.csim.service.GetQueueSessionCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_cssession;
import com.ymttest.database.model.ymt_queuesession;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_queuesessionWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
/**
*查询会话队列
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetQueueSession{
	private static GetQueueSessionBean bean;
	private static GetQueueSessionCall call;
	private CsimCallService service=new CsimCallService();
	private static Integer userId=Integer.parseInt(EnvSetup.getData("userId_IM").toString());
	private Integer sellerId=Integer.parseInt(EnvSetup.getData("autotest_seller1").toString());
	private static ymt_queuesessionWapper queuesessionWapper=new ymt_queuesessionWapper();
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询会话队列");
	}

	@Before
	public void caseUp() {
		bean=new GetQueueSessionBean();
		call=new GetQueueSessionCall();
		queuesessionWapper.deleteAll();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetQueueSession_1() {
		Logger.start(true,"查询会话队列-客服类型是买家");
		try {
			//发消息
			SendMessageBean sendMessageBean=service.setSendMessageBean();
			sendMessageBean.setUserId(userId);
			service.setSendMessageCall(sendMessageBean);
			
			bean.setCsType(0);
			bean.setCallType(0);
			call.setData(bean);
			call.callService();	
			//验证
			List<ymt_queuesession> queuesessionList=queuesessionWapper.getTopListByUserTypeAndCallType(MapUtil.hashMap("userType",bean.getCsType(),
					"callType",bean.getCallType(),"top",50));
			List<queuesession> queuesessionCall=call.getQueuesessionList().getResult();
			Logger.verifyEquals("200", call.getStatus(), "验证返回的Status一致");
			Logger.verifyEquals(queuesessionList.size(), queuesessionCall.size(), "验证返回的数据与数据库一致");
			for(int i=0;i<queuesessionList.size();i++)
			{
				Logger.verifyEquals(queuesessionCall.get(i).getId(), queuesessionList.get(i).getId(), "验证返回的id与数据库ymt_queuesession表中的id是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getUserId(), queuesessionList.get(i).getUserId(), "验证返回的UserId与数据库ymt_queuesession表中的UserId是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getBeginTime(), dateFormat.format(queuesessionList.get(i).getBeginTime()), "验证返回的BeginTime与数据库ymt_queuesession表中的BeginTime是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getOpenType(), queuesessionList.get(i).getOpenType(), "验证返回的OpenType与数据库ymt_queuesession表中的OpenType是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getFromPlatform(), queuesessionList.get(i).getFromPlatform(), "验证返回的FromPlatform与数据库ymt_queuesession表中的FromPlatform是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getPriority(), queuesessionList.get(i).getPriority(), "验证返回的Priority与数据库ymt_queuesession表中的Priority是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getUnReadCount(), queuesessionList.get(i).getUnReadCount(), "验证返回的UnReadCount与数据库ymt_queuesession表中的UnReadCount是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getLastMessage(), queuesessionList.get(i).getLastMessage(), "验证返回的LastMessage与数据库ymt_queuesession表中的LastMessage是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getLastMessageTime(), dateFormat.format(queuesessionList.get(i).getLastMessageTime()), "验证返回的LastMessageTime与数据库ymt_queuesession表中的LastMessageTime是否一致");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetQueueSession_2() {
		Logger.start(true,"查询会话队列-客服类型是买手");
		try {
			//发消息
			SendMessageBean sendMessageBean=service.setSendMessageBean();
			sendMessageBean.setUserId(sellerId);
			service.setSendMessageCall(sendMessageBean);
			
			bean.setCsType(1);
			bean.setCallType(0);
			call.setData(bean);
			call.callService();	
			//验证
			List<ymt_queuesession> queuesessionList=queuesessionWapper.getTopListByUserTypeAndCallType(MapUtil.hashMap("userType",bean.getCsType(),
					"callType",bean.getCallType(),"top",50));
			List<queuesession> queuesessionCall=call.getQueuesessionList().getResult();
			Logger.verifyEquals("200", call.getStatus(), "验证返回的Status一致");
			Logger.verifyEquals(queuesessionList.size(), queuesessionCall.size(), "验证返回的数据与数据库一致");
			for(int i=0;i<queuesessionList.size();i++)
			{
				Logger.verifyEquals(queuesessionCall.get(i).getId(), queuesessionList.get(i).getId(), "验证返回的id与数据库ymt_queuesession表中的id是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getUserId(), queuesessionList.get(i).getUserId(), "验证返回的UserId与数据库ymt_queuesession表中的UserId是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getBeginTime(), dateFormat.format(queuesessionList.get(i).getBeginTime()), "验证返回的BeginTime与数据库ymt_queuesession表中的BeginTime是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getOpenType(), queuesessionList.get(i).getOpenType(), "验证返回的OpenType与数据库ymt_queuesession表中的OpenType是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getFromPlatform(), queuesessionList.get(i).getFromPlatform(), "验证返回的FromPlatform与数据库ymt_queuesession表中的FromPlatform是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getPriority(), queuesessionList.get(i).getPriority(), "验证返回的Priority与数据库ymt_queuesession表中的Priority是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getUnReadCount(), queuesessionList.get(i).getUnReadCount(), "验证返回的UnReadCount与数据库ymt_queuesession表中的UnReadCount是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getLastMessage(), queuesessionList.get(i).getLastMessage(), "验证返回的LastMessage与数据库ymt_queuesession表中的LastMessage是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getLastMessageTime(), dateFormat.format(queuesessionList.get(i).getLastMessageTime()), "验证返回的LastMessageTime与数据库ymt_queuesession表中的LastMessageTime是否一致");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetQueueSession_3() {
		Logger.start(true,"查询会话队列-验证队列表ymt_queuesession 中仅有买家会话队列，传入CsType 类型是买手");
		try {
			//发消息
			SendMessageBean sendMessageBean=service.setSendMessageBean();
			sendMessageBean.setUserId(userId);
			service.setSendMessageCall(sendMessageBean);
			
			bean.setCsType(1);
			bean.setCallType(0);
			call.setData(bean);
			call.callService();	
			//验证
			List<ymt_queuesession> queuesessionList=queuesessionWapper.getTopListByUserTypeAndCallType(MapUtil.hashMap("userType",bean.getCsType(),
					"callType",bean.getCallType(),"top",50));
			List<queuesession> queuesessionCall=call.getQueuesessionList().getResult();
			Logger.verifyEquals("200", call.getStatus(), "验证返回的Status一致");
			Logger.verifyEquals(0, queuesessionCall.size(), "验证返回的数据与数据库一致");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetQueueSession_4() {
		Logger.start(true,"查询会话队列-验证队列表ymt_queuesession 中仅有买手会话队列，传入CsType 类型是买家");
		try {
			//发消息
			SendMessageBean sendMessageBean=service.setSendMessageBean();
			sendMessageBean.setUserId(sellerId);
			service.setSendMessageCall(sendMessageBean);
			
			bean.setCsType(0);
			bean.setCallType(0);
			call.setData(bean);
			call.callService();	
			//验证
			List<ymt_queuesession> queuesessionList=queuesessionWapper.getTopListByUserTypeAndCallType(MapUtil.hashMap("userType",bean.getCsType(),
					"callType",bean.getCallType(),"top",50));
			List<queuesession> queuesessionCall=call.getQueuesessionList().getResult();
			Logger.verifyEquals("200", call.getStatus(), "验证返回的Status一致");
			Logger.verifyEquals(0, queuesessionCall.size(), "验证返回的数据与数据库一致");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetQueueSession_5() {
		Logger.start(true,"查询会话队列-验证队列表ymt_queuesession 中买手和买家会话队列同时存在，传入CsType 类型是买家");
		try {
			//发消息
			SendMessageBean sendMessageBean=service.setSendMessageBean();
			sendMessageBean.setUserId(sellerId);
			service.setSendMessageCall(sendMessageBean);
			
			sendMessageBean.setUserId(userId);
			service.setSendMessageCall(sendMessageBean);
			
			bean.setCsType(0);
			bean.setCallType(0);
			call.setData(bean);
			call.callService();	
			//验证
			List<ymt_queuesession> queuesessionList=queuesessionWapper.getTopListByUserTypeAndCallType(MapUtil.hashMap("userType",bean.getCsType(),
					"callType",bean.getCallType(),"top",50));
			List<queuesession> queuesessionCall=call.getQueuesessionList().getResult();
			Logger.verifyEquals("200", call.getStatus(), "验证返回的Status一致");
			Logger.verifyEquals(1, queuesessionCall.size(), "验证返回的数据与数据库一致");
			for(int i=0;i<queuesessionList.size();i++)
			{
				Logger.verifyEquals(queuesessionCall.get(i).getUserId(), userId, "验证返回的UserId与数据库ymt_queuesession表中的UserId是否一致");
				
				Logger.verifyEquals(queuesessionCall.get(i).getId(), queuesessionList.get(i).getId(), "验证返回的id与数据库ymt_queuesession表中的id是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getBeginTime(), dateFormat.format(queuesessionList.get(i).getBeginTime()), "验证返回的BeginTime与数据库ymt_queuesession表中的BeginTime是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getOpenType(), queuesessionList.get(i).getOpenType(), "验证返回的OpenType与数据库ymt_queuesession表中的OpenType是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getFromPlatform(), queuesessionList.get(i).getFromPlatform(), "验证返回的FromPlatform与数据库ymt_queuesession表中的FromPlatform是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getPriority(), queuesessionList.get(i).getPriority(), "验证返回的Priority与数据库ymt_queuesession表中的Priority是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getUnReadCount(), queuesessionList.get(i).getUnReadCount(), "验证返回的UnReadCount与数据库ymt_queuesession表中的UnReadCount是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getLastMessage(), queuesessionList.get(i).getLastMessage(), "验证返回的LastMessage与数据库ymt_queuesession表中的LastMessage是否一致");
				Logger.verifyEquals(queuesessionCall.get(i).getLastMessageTime(), dateFormat.format(queuesessionList.get(i).getLastMessageTime()), "验证返回的LastMessageTime与数据库ymt_queuesession表中的LastMessageTime是否一致");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}